from datetime import datetime
from enum import Enum


# 订单状态枚举
class OrderStatus(Enum):
    CREATE = "CREATE"
    PAID = "PAID"
    SHIPPING = "SHIPPING"
    DELIVERED = "DELIVERED"
    CANCEL = "CANCEL"


class Customer:
    """客户类"""
    def __init__(self, name, contact, delivery_address, active=True):
        self.name = name
        self.contact = contact
        self.delivery_address = delivery_address
        self.active = active
        self.orders = []  # 关联的订单

    def add_order(self, order):
        if isinstance(order, Order):
            self.orders.append(order)


class Product:
    """商品类"""
    def __init__(self, title, weight, description, price):
        self.title = title
        self.weight = weight
        self.description = description
        self.price = price  # 单价

    def getPriceForQuantity(self, quantity):
        """计算指定数量的总价"""
        return self.price * quantity

    def getWeight(self):
        """获取商品重量"""
        return self.weight

    def __str__(self):
        return f"Product({self.title})"


class OrderDetail:
    """订单详情类"""
    def __init__(self, product, quantity):
        self.product = product  # 关联商品
        self.quantity = quantity

    def calculateSubTotal(self):
        """计算小计（商品总价）"""
        return self.product.getPriceForQuantity(self.quantity)

    def calculateWeight(self):
        """计算商品总重量"""
        return self.product.getWeight() * self.quantity

    def __str__(self):
        return f"OrderDetail({self.product.title}, {self.quantity})"


class Payment:
    """支付方式父类"""
    def __init__(self, amount):
        self.amount = amount


class Credit(Payment):
    """信用卡支付"""
    def __init__(self, amount, number, type_, expire_date):
        super().__init__(amount)
        self.number = number
        self.type = type_
        self.expire_date = expire_date

    def __str__(self):
        return f"CreditPayment(amount={self.amount}, card={self.number})"


class Cash(Payment):
    """现金支付"""
    def __init__(self, amount, cash_tendered):
        super().__init__(amount)
        self.cash_tendered = cash_tendered

    def __str__(self):
        return f"CashPayment(amount={self.amount}, tendered={self.cash_tendered})"


class WireTransfer(Payment):
    """在线转账"""
    def __init__(self, amount, bank_id, bank_name):
        super().__init__(amount)
        self.bank_id = bank_id
        self.bank_name = bank_name

    def __str__(self):
        return f"WireTransfer(amount={self.amount}, bank={self.bank_name})"


class AliPay(Payment):
    """支付宝支付"""
    def __init__(self, amount, number):
        super().__init__(amount)
        self.number = number

    def __str__(self):
        return f"AliPay(amount={self.amount}, account={self.number})"


class WeixinPay(Payment):
    """微信支付"""
    def __init__(self, amount, number):
        super().__init__(amount)
        self.number = number

    def __str__(self):
        return f"WeixinPay(amount={self.amount}, account={self.number})"


class Order:
    """订单类"""
    def __init__(self, customer, create_date=None, status=OrderStatus.CREATE):
        self.customer = customer  # 关联客户
        self.create_date = create_date or datetime.now()
        self.status = status
        self.order_details = []  # 订单详情列表
        self.payment = None      # 关联支付方式
        customer.add_order(self)

    def add_detail(self, order_detail):
        """添加订单详情"""
        if isinstance(order_detail, OrderDetail):
            self.order_details.append(order_detail)

    def set_payment(self, payment):
        """设置支付方式"""
        if isinstance(payment, Payment):
            self.payment = payment

    def get_total_amount(self):
        """计算订单总金额"""
        return sum(detail.calculateSubTotal() for detail in self.order_details)

    def __str__(self):
        return f"Order(createDate={self.create_date.strftime('%Y-%m-%d')}, status={self.status.value})"


# 测试代码
if __name__ == "__main__":
    # 创建客户
    customer = Customer("Alice", "123456789", "123 Main St, City")

    # 创建商品
    product1 = Product("Laptop", 2.5, "High-performance laptop", 8000)
    product2 = Product("Mouse", 0.2, "Wireless mouse", 200)

    # 创建订单
    order = Order(customer)

    # 添加订单详情
    detail1 = OrderDetail(product1, 1)
    detail2 = OrderDetail(product2, 2)
    order.add_detail(detail1)
    order.add_detail(detail2)

    # 设置支付方式（信用卡）
    payment = Credit(order.get_total_amount(), "1234-5678-9012-3456", "Visa", "12/26")
    order.set_payment(payment)
    order.status = OrderStatus.PAID

    # 打印订单信息
    print(f"客户: {customer.name}")
    print(f"订单: {order}")
    print(f"订单详情:")
    for detail in order.order_details:
        print(f"  - {detail}, 小计: {detail.calculateSubTotal()}元, 重量: {detail.calculateWeight()}kg")
    print(f"订单总金额: {order.get_total_amount()}元")
    print(f"支付方式: {order.payment}")